Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jbox2d.testbed
Class AbstractExample

    java.lang.Object
      org.jbox2d.testbed.AbstractExample

    public abstract class AbstractExample

extends java.lang.Object

Field Summary
`static javax.vecmath.Color3f` | `black`
`static javax.vecmath.Color3f` | `blue`
`protected boolean` | `bombSpawning` True if a bomb has started spawning but has not been created yet.
`protected Vec2` | `bombSpawnPoint` The point at which we will place a bomb when completeBombSpawn() is called.
`float` | `cachedCamScale` Saved camera variable so that camera stays put between reloads of example.
`float` | `cachedCamX` Saved camera variable so that camera stays put between reloads of example.
`float` | `cachedCamY` Saved camera variable so that camera stays put between reloads of example.
`static javax.vecmath.Color3f` | `gray`
`static javax.vecmath.Color3f` | `green`
`boolean` | `hasCachedCamera` Have the cachedCam* variables been set for this example?
`static java.lang.String` | `instructionString` General instructions that apply to all tests.
`boolean[]` | `keyDown` Array of key states, by char value.
`protected Body` | `m_bomb` The bomb body.
`protected BoundaryListener` | `m_boundaryListener` Listener for world AABB violations.
`protected ContactListener` | `m_contactListener` Listener for contact events.
`DebugDraw` | `m_debugDraw` Used for drawing
`protected DestructionListener` | `m_destructionListener` Listener for body and joint destructions.
`protected MouseJoint` | `m_mouseJoint` Mouse joint.
`protected int` | `m_pointCount` Number of active points in m_points array.
`protected org.jbox2d.testbed.AbstractExample.ContactPoint[]` | `m_points` Array of contact points - use m_pointCount to get number of active elements.
`protected int` | `m_textLine` Y-pixel value that marks bottom of text to be drawn.
`protected World` | `m_world` The world object this example uses.
`protected AABB` | `m_worldAABB` The bounding box for the world.
`float` | `memFree` The exponentially smoothed amount of free memory available to the JVM.
`Vec2` | `mouseScreen` Screen coordinates of mouse
`Vec2` | `mouseWorld` World coordinates of mouse
`protected boolean` | `needsReset` True if we should reset the demo for the next frame.
`boolean[]` | `newKeyDown` Same as keyDown, but true only if the key was newly pressed this frame.
`TestbedMain` | `parent` The controller that the AbstractExample runs in
`boolean` | `pmousePressed` Was the mouse pressed last frame? True if either right or left button was down.
`Vec2` | `pmouseScreen` Screen coordinates of mouse on last frame
`static javax.vecmath.Color3f` | `red`
`protected TestSettings` | `settings` Settings for this example.
`static int` | `textLineHeight` Height of font used to draw text.
`static javax.vecmath.Color3f` | `white`

Constructor Summary
`AbstractExample(TestbedMain _parent)` Instantiate the test.

Method Summary
`void` | `boundaryViolated(Body body)` Stub method for concrete examples to override if desired.
`void` | `completeBombSpawn()` Creates and launches a bomb using the current bomb and mouse locations to "slingshot" it.
`abstract void` | `create()` Create the world geometry for each test.
`void` | `createWorld()` Overload this if you need to create a different world AABB or gravity vector
`java.lang.String` | `getExampleInstructions()` Returns a string containing example instructions.
`abstract java.lang.String` | `getName()`
`void` | `initialize()` Should not usually be overloaded.
`void` | `jointDestroyed(Joint joint)` Stub method for concrete examples to override if desired.
`void` | `keyPressed(int key)` Set keyDown and newKeyDown arrays when we get a keypress.
`void` | `keyReleased(int key)` Set keyDown array when we get a key release.
`void` | `launchBomb()` Space launches a bomb from a random default position.
`void` | `launchBomb(Vec2 position, Vec2 velocity)` Launch bomb from a specific position with a given velocity.
`void` | `mouseDown(Vec2 p)` Handle mouseDown events.
`void` | `mouseMove(Vec2 p)` Handle mouseMove events (TestbedMain also sends mouseDragged events here)
`void` | `mouseUp()` Handle mouseUp events.
`void` | `postStep()` Stub for overloading in examples - called after physics step.
`void` | `preStep()` Stub for overloading in examples - called before physics step.
`void` | `printInstructions()` Prints default instructions + specific example instructions.
`void` | `setCamera(float x, float y, float scale)` Sets the camera target and scale.
`void` | `spawnBomb(Vec2 worldPt)` Begins spawning a bomb, spawn finishes and bomb is created upon calling completeBombSpawn().
`void` | `step()` Take a physics step.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### parent

    public TestbedMain parent

  The controller that the AbstractExample runs in

### m_debugDraw

    public DebugDraw m_debugDraw

  Used for drawing

### keyDown

    public boolean[] keyDown

  Array of key states, by char value. Does not include arrows or modifier keys.

### newKeyDown

    public boolean[] newKeyDown

  Same as keyDown, but true only if the key was newly pressed this frame.

### instructionString

    public static java.lang.String instructionString

  General instructions that apply to all tests.

### mouseScreen

    public Vec2 mouseScreen

  Screen coordinates of mouse

### mouseWorld

    public Vec2 mouseWorld

  World coordinates of mouse

### pmouseScreen

    public Vec2 pmouseScreen

  Screen coordinates of mouse on last frame

### pmousePressed

    public boolean pmousePressed

  Was the mouse pressed last frame? True if either right or left button was down.

### needsReset

    protected boolean needsReset

  True if we should reset the demo for the next frame.

### bombSpawnPoint

    protected Vec2 bombSpawnPoint

  The point at which we will place a bomb when completeBombSpawn() is called.

### bombSpawning

    protected boolean bombSpawning

  True if a bomb has started spawning but has not been created yet.

### m_textLine

    protected int m_textLine

  Y-pixel value that marks bottom of text to be drawn.

### m_pointCount

    protected int m_pointCount

  Number of active points in m_points array.

### m_points

    protected org.jbox2d.testbed.AbstractExample.ContactPoint[] m_points

  Array of contact points - use m_pointCount to get number of active elements.

### m_world

    protected World m_world

  The world object this example uses.

### m_bomb

    protected Body m_bomb

  The bomb body. May be null if no bomb is active.

### m_mouseJoint

    protected MouseJoint m_mouseJoint

  Mouse joint. May be null if mouse is not attached to anything.

### settings

    protected TestSettings settings

  Settings for this example. This is stored and reloaded when the example restarts or we come back from another example.

### m_worldAABB

    protected AABB m_worldAABB

  The bounding box for the world. If the defaults do not work for you, overload createWorld() and set the AABB appropriately there.

### memFree

    public float memFree

  The exponentially smoothed amount of free memory available to the JVM.

### m_destructionListener

    protected DestructionListener m_destructionListener

  Listener for body and joint destructions.

### m_boundaryListener

    protected BoundaryListener m_boundaryListener

  Listener for world AABB violations.

### m_contactListener

    protected ContactListener m_contactListener

  Listener for contact events.

### white

    public static javax.vecmath.Color3f white

### black

    public static javax.vecmath.Color3f black

### gray

    public static javax.vecmath.Color3f gray

### red

    public static javax.vecmath.Color3f red

### green

    public static javax.vecmath.Color3f green

### blue

    public static javax.vecmath.Color3f blue

### cachedCamX

    public float cachedCamX

  Saved camera variable so that camera stays put between reloads of example.

### cachedCamY

    public float cachedCamY

  Saved camera variable so that camera stays put between reloads of example.

### cachedCamScale

    public float cachedCamScale

  Saved camera variable so that camera stays put between reloads of example.

### hasCachedCamera

    public boolean hasCachedCamera

  Have the cachedCam* variables been set for this example?

### textLineHeight

    public static int textLineHeight

  Height of font used to draw text.

Constructor Detail

### AbstractExample

    public AbstractExample(TestbedMain _parent)

  Instantiate the test.

  Parameters:
    `_parent` - The controller that this test is run from.

Method Detail

### printInstructions

    public void printInstructions()

  Prints default instructions + specific example instructions. To add instructions to your example, override getExampleInstructions()

### getExampleInstructions

    public java.lang.String getExampleInstructions()

  Returns a string containing example instructions. Overload within an example to provide special instructions or information.

  Returns:
    A string containing example instructions

### getName

    public abstract java.lang.String getName()

  Returns:
    Title of example.

### create

    public abstract void create()

  Create the world geometry for each test. Any custom initialization for a test should go here. Called immediately after initialize(), which handles generic test initialization and should usually not be overloaded.

### createWorld

    public void createWorld()

  Overload this if you need to create a different world AABB or gravity vector

### initialize

    public void initialize()

  Should not usually be overloaded. Performs initialization tasks common to most examples:
  - Resets input state
  - Initializes member variables
  - Sets test settings
  - Creates world, gravity and AABB by calling createWorld() - overload that if you are unhappy with defaults
  - Sets up and attaches listeners
  - Sets up drawing
  - Sets camera to default or saved state
  - Calls create() to set up test

### step

    public void step()

  Take a physics step. This is the guts of the simulation loop. When creating your own game, you will likely want to

### preStep

    public void preStep()

  Stub for overloading in examples - called before physics step.

### postStep

    public void postStep()

  Stub for overloading in examples - called after physics step.

### launchBomb

    public void launchBomb()

  Space launches a bomb from a random default position.

### launchBomb

    public void launchBomb(Vec2 position,
                           Vec2 velocity)

  Launch bomb from a specific position with a given velocity.

  Parameters:
    `position` - Position to launch bomb from.
    `velocity` - Velocity to launch bomb with.

### spawnBomb

    public void spawnBomb(Vec2 worldPt)

  Begins spawning a bomb, spawn finishes and bomb is created upon calling completeBombSpawn(). When a bomb is spawning, it is not an active body but its position is stored so it may be drawn.

### completeBombSpawn

    public void completeBombSpawn()

  Creates and launches a bomb using the current bomb and mouse locations to "slingshot" it.

### keyPressed

    public void keyPressed(int key)

  Set keyDown and newKeyDown arrays when we get a keypress.

  Parameters:
    `key` - The key pressed.

### keyReleased

    public void keyReleased(int key)

  Set keyDown array when we get a key release.

  Parameters:
    `key` - The key released.

### mouseDown

    public void mouseDown(Vec2 p)

  Handle mouseDown events.

  Parameters:
    `p` - The screen location that the mouse is down at.

### mouseUp

    public void mouseUp()

  Handle mouseUp events.

### mouseMove

    public void mouseMove(Vec2 p)

  Handle mouseMove events (TestbedMain also sends mouseDragged events here)

  Parameters:
    `p` - The new mouse location (screen coordinates)

### setCamera

    public void setCamera(float x,
                          float y,
                          float scale)

  Sets the camera target and scale.

  Parameters:
    `x` - World x coordinate of camera focus
    `y` - World y coordinate of camera focus
    `scale` - Size in screen units (usually pixels) of one world unit (meter)

### jointDestroyed

    public void jointDestroyed(Joint joint)

  Stub method for concrete examples to override if desired. Called when a joint is implicitly destroyed due to body destruction.

  Parameters:
    `joint` - The implicitly destroyed joint

### boundaryViolated

    public void boundaryViolated(Body body)

  Stub method for concrete examples to override if desired. Called when a body leaves the world boundary.

  Parameters:
    `body` - The body that went out of bounds

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD